Public Class LoginForm
    Public userID As String
    Public admin As Boolean
    Private x, y As Integer
    Public login As Boolean
    Public confirm As Boolean
    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim ds As DataSet
        login = False
        admin = False
        userID = UsernameTextBox.Text
        If UsernameTextBox.Text = "" Then
            MsgBox("Enter a UserID !!!")
            Exit Sub
        End If

        ds = db.getvalue("select * from users where userid = '" & Trim(UsernameTextBox.Text.Replace("'", "''")) & "'")
        If ds.Tables(0).Rows.Count = 0 Then
            MsgBox("UserID is not availabe!")
            Exit Sub
        End If
        If ds.Tables(0).Rows(0).Item("uactive") = 0 Then
            MsgBox("UserID is disabled.")
            Exit Sub
        End If


        If Decode(ds.Tables(0).Rows(0).Item("upassword")) <> PasswordTextBox.Text Then
            MsgBox("UserID or Password is not correct")
            Exit Sub
        End If
        admin = ds.Tables(0).Rows(0).Item("uadmin")
        login = True
        confirm = IIf(IsDBNull(ds.Tables(0).Rows(0).Item("uconfirm")), False, ds.Tables(0).Rows(0).Item("uconfirm"))
        Me.DialogResult = Windows.Forms.DialogResult.OK
        'FrMain.Show()
        UsernameTextBox.Focus()
        Me.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Dispose()
    End Sub


    Private Sub LoginForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        PasswordTextBox.Text = Nothing
        UsernameTextBox.Text = Nothing


        'Panel1.Top = 0
        'Panel1.Left = 0
        'Panel1.Width = Me.Width
        'Panel1.Height = Me.Height
        'LogoPictureBox.Top = 1
        'LogoPictureBox.Left = 1

    End Sub



    Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Label1.Cursor = Cursors.NoMove2D
            x = MousePosition.X
            y = MousePosition.Y
        End If
    End Sub

  
    Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            'MsgBox("left move")
        End If
    End Sub

    Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Left And (x > 0 Or y > 0) Then
            Me.Location = New Point(MousePosition.X - (x - Me.Location.X), MousePosition.Y - (y - Me.Location.Y))
            Label1.Cursor = Cursors.Default

        End If
        x = 0
        y = 0
    End Sub



End Class
